//Hello world!!!
import React, { Component } from 'react'
import { Text, View } from 'react-native'
import WebView from 'react-native-webview'
import {NavigationContainer} from '@react-navigation/native'
import {createStackNavigator} from '@react-navigation/stack'

class Login extends Component{
  _recieve=msg=>{
    let user=JSON.parse(msg.nativeEvent.data)
    
    this.props.navigation.navigate('Suc',{user})
  }
  render(){
    return <View style={{flex:1}}>
      <WebView onMessage={this._recieve} source={{uri:'http://192.168.31.164:3000/login.html'}}/>

    </View>
  }
}
class Suc extends Component{
  // componentDidMount(){
  //   this.user=this.props.route.params.user
  //   this.script="alert(200)"
  // }
  render(){
    let user=this.props.route.params.user
    console.log(user)
    
    // let script=`document.querySelector("h2").innerHTML=${user.psd}`
    let script=`fn(${JSON.stringify(user)})`
    return <View style={{flex:1}}>
      <WebView scrip injectedJavaScript={script} source={{uri:'http://192.168.31.164:3000/suc.html'}}/>
    </View>
  }
}
export default class App extends Component {
  render() {
    let Stack=createStackNavigator()
    return <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Login" component={Login}/>
        <Stack.Screen name="Suc" component={Suc}/>
      </Stack.Navigator>
    </NavigationContainer>
  }
}
